package lab02.Text13;

public class Gymnastics extends ComputerAverage {
    //行为：去掉一个最低分，去掉一个最高分，然后求平均分
    double data[];

    Gymnastics() {
    }

    Gymnastics(double data[]) {
        this.data = data;
    }

    @Override
    double average(double[] data) {
        double max, min;
        int k1=0, k2=0;
        max=min=data[0];
        for(int i=0;i<data.length;i++){
            if(data[i]>max){
                max=data[i];
                k1=i;
            }
            else if(data[i]<min){
                min=data[i];
                k2=i;
            }
        }
        data[k1]=0;
        data[k2]=0;
        double sum=0;
        for(int i=0;i<data.length;i++){
            sum+=data[i];
        }
        sum=sum/(data.length-2);
        return sum;
    }

}